import os, requests, pandas as pd

# 1. 读 Excel
df = pd.read_excel('bilibili_top100.xlsx')

# 2. 建封面文件夹
os.makedirs('covers', exist_ok=True)

# 3. 循环下载封面
for _, row in df.iterrows():
    url = row['封面']          # 稍后要加的列
    filename = f"covers/{row['排名']:03d}_{row['UP主']}.jpg"
    if not os.path.exists(filename):
        img = requests.get(url, headers={'User-Agent': 'Mozilla/5.0'}).content
        with open(filename, 'wb') as f:
            f.write(img)
        print(f'已下载 {filename}')
    else:
        print(f'已存在 {filename}')

print('全部封面下载完成！')